<html>
<head>
<style>
  button {
    -webkit-app-region: no-drag;
  }
</style>
</head>
<body style="-webkit-user-select: none; -webkit-app-region: drag">
<script>
  var gui = require('nw.gui');
  var win = gui.Window.open('popup.html', {
    x: 100, y: 100, width: 200, height: 300
  });

  win.on('closed', function() {
    console.log('popup window is closed.');
    win = null;
  });

  win.on('loading', function() {
    console.log('start to load new window.');
  });

  win.on('loaded', function() {
    console.log('new window loaded.');
  });

  function takeSnapshot() {
    gui.Window.get().capturePage(function(img) {
      var image = win.window.document.getElementById('image');
      image.src = img;
           
    }, 'png');
  }
  
  gui.Window.get().on('close', function() {
    if (win != null)
      win.close(true);
    this.close(true);
  });

  gui.Window.get().show();
</script>
<button onclick="win.focus()">Focus</button>
<br/>
<button onclick="win.blur()">Blur</button>
<br/>
<button onclick="win.show()">Show</button>
<br/>
<button onclick="win.hide()">Hide</button>
<br/>
<button onclick="win.maximize()">Maximize</button>
<br/>
<button onclick="win.unmaximize()">Unmaximize</button>
<br/>
<button onclick="win.minimize()">Minimize</button>
<br/>
<button onclick="win.restore()">Restore</button>
<br/>
<button onclick="win.enterFullscreen()">EnterFullscreen</button>
<br/>
<button onclick="win.leaveFullscreen()">LeaveFullscreen</button>
<br/>
<button onclick="win.close()">Close</button>
<br/>
<button onclick="win.close(true)">Force Close</button>
<br/>
<button onclick="win.showDevTools()">Open DevTools</button>
<br/>
<button onclick="win.setMinimumSize(100, 200)">setMinimumSize(100, 200)</button>
<br/>
<button onclick="win.setMaximumSize(200, 400)">setMaximumSize(200, 400)</button>
<br/>
<button onclick="win.moveTo(0, 0)">moveTo(0, 0)</button>
<br/>
<button onclick="win.moveBy(10, 20)">moveBy(10, 20)</button>
<br/>
<button onclick="win.resizeTo(100, 100)">resizeTo(100, 100)</button>
<br/>
<button onclick="win.resizeBy(10, 20)">resizeBy(10, 20)</button>
<br/>
<button onclick="win.setResizable(true)">setResizable(true)</button>
<button onclick="win.setResizable(false)">(false)</button>
<br/>
<p>Focus another application within 2sec, popup window should on top.</p>
<button onclick="setTimeout(function(){win.setAlwaysOnTop(true);},2000)">setAlwaysOnTop(true)</button>
<button onclick="win.setAlwaysOnTop(false)">(false)</button>
<br/>
<button onclick="win.zoomLevel = 2">set zoomLevel to 2</button>
<br/>
<button onclick="win.zoomLevel = 0">set zoomLevel to 0</button>
<br/>
<button onclick="takeSnapshot()">takeSnapshot</button> 
<br/>
Reload the window and do all tests again.
<button onclick="win.reload()">Reload</button>
</body>
</html>
